package com.o2opays.wechat.tool;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * JSON工具类
 * 
 * @author 114010269
 */
public class JsonUtil {

    //测试提交

    public static <T> String toJson(T obj) {
        GsonBuilder gb = new GsonBuilder();
        Gson g = gb.create();
        String t = g.toJson(obj);
        return t;
    }

    public static <T> T toObject(String jsonString, Class<T> element) {
        if (StringUtils.isEmpty(jsonString)) {
            return null;
        }
        GsonBuilder gb = new GsonBuilder();
        Gson g = gb.create();
        T t = g.fromJson(jsonString,element);
        return t;
    }
}